package ch.rheintalconnection.sysventory.businessServices;

import java.net.ConnectException;
import java.net.UnknownHostException;
import java.util.concurrent.Callable;

import ch.rheintalconnection.sysventory.domain.ScanEntry;
import ch.rheintalconnection.sysventory.dto.DtoContainer;
import ch.rheintalconnection.sysventory.technicalServices.IDataReader;
import ch.rheintalconnection.sysventory.technicalServices.IHostScanner;

public class DomainHostScanner implements Callable<ScanEntry> {
	
	private IHostScanner hostScanner;
	private IDataReader dataReader;
	
	public DomainHostScanner(IHostScanner hostScanner, IDataReader dataReader) {
		
		this.hostScanner = hostScanner;
		this.dataReader = dataReader;
		
	}
	
	@Override
	public ScanEntry call() throws Exception {
		
		return scan();
	}
	
	private ScanEntry scan() throws UnknownHostException, ConnectException {
		
		DtoContainer dtos = hostScanner.scan();
		
		DtoToDomainConverter dtoToDomainConverter = new DtoToDomainConverter(dataReader);
		ScanEntry scanEntry = dtoToDomainConverter.toScanEntry(dtos);
		

		return scanEntry;
	}

}
